const fs = require('fs')
const router = require('express').Router()
const logger = require('log4js').getLogger()

let userDao = require('../dao/user')

router.get('/', function (req, res) {
  // res.sendFile('src/views/index.html', {root: process.cwd()})
  res.render('index')
})

router.post('/admin/getUser', function (req, res) {
  let id = req.body.id
  console.log('session', req.session)
  req.session.user = {
    id,
    name: 'zhangsan'
  }
  let result = JSON.parse(fs.readFileSync('public/json/demo.json', 'utf-8'))
  res.send(result)
})

router.post('/admin/queryInfo', function (req, res) {
  let sql = 'select * from user where id=' + req.body.id
  userDao.query(sql).then((results) => {
    res.send({success: true, data: results[0]})
  })
})

module.exports = router
